<template>
  <teleport to="body">
    <div class="notification-container">
      <transition-group name="notification" tag="div">
        <div
          v-for="notification in appStore.notifications"
          :key="notification.id"
          :class="[
            'notification',
            `notification--${notification.type}`
          ]"
        >
          <div class="notification__icon">
            <i :class="getIconClass(notification.type)"></i>
          </div>
          <div class="notification__content">
            <div class="notification__title">{{ notification.title }}</div>
            <div class="notification__message">{{ notification.message }}</div>
          </div>
          <div class="notification__close">
            <el-button
              text
              :icon="Close"
              size="small"
              @click="appStore.removeNotification(notification.id)"
            />
          </div>
        </div>
      </transition-group>
    </div>
  </teleport>
</template>

<script setup>
import { Close } from '@element-plus/icons-vue'
import { useAppStore } from '@/stores/app'

const appStore = useAppStore()

const getIconClass = (type) => {
  const icons = {
    success: 'el-icon-success-filled',
    error: 'el-icon-error-filled',
    warning: 'el-icon-warning-filled',
    info: 'el-icon-info-filled'
  }
  return icons[type] || icons.info
}
</script>

<style scoped lang="scss">
.notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  pointer-events: none;
}

.notification {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  margin-bottom: 12px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-left: 4px solid;
  max-width: 400px;
  pointer-events: all;
  
  &--success {
    border-left-color: var(--el-color-success);
    
    .notification__icon {
      color: var(--el-color-success);
    }
  }
  
  &--error {
    border-left-color: var(--el-color-error);
    
    .notification__icon {
      color: var(--el-color-error);
    }
  }
  
  &--warning {
    border-left-color: var(--el-color-warning);
    
    .notification__icon {
      color: var(--el-color-warning);
    }
  }
  
  &--info {
    border-left-color: var(--el-color-info);
    
    .notification__icon {
      color: var(--el-color-info);
    }
  }
}

.notification__icon {
  font-size: 20px;
  margin-top: 2px;
}

.notification__content {
  flex: 1;
  
  .notification__title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: var(--el-text-color-primary);
  }
  
  .notification__message {
    font-size: 13px;
    color: var(--el-text-color-regular);
    line-height: 1.4;
  }
}

.notification__close {
  margin-top: -4px;
}

// 动画效果
.notification-enter-active,
.notification-leave-active {
  transition: all 0.3s ease;
}

.notification-enter-from {
  opacity: 0;
  transform: translateX(100%);
}

.notification-leave-to {
  opacity: 0;
  transform: translateX(100%);
}

.notification-move {
  transition: transform 0.3s ease;
}
</style>